package com.cdn.allmobilestore.adapter;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.cdn.allmobilestore.R;
import com.cdn.allmobilestore.model.HomeInfo;
import com.cdn.allmobilestore.ui.HomeListItem;


public class HomeAdapter extends BaseDataAdapter<HomeInfo>
{
  private static final int LIST_ITEM_TYPE_COUNT = 2;
  private static final int LIST_ITEM_TYPE_HEADER = 0;
  private static final int LIST_ITEM_TYPE_ITEM = 1;
  private int mHeaderViewCount;

  public HomeAdapter(Context context, int headerViewCount)
  {
    super(context);
    this.mHeaderViewCount = headerViewCount;
   
  }

  public void bindView(View view, int position, HomeInfo data)
  {
     if (position < this.mHeaderViewCount)
    	 return;
     else           
      if (view instanceof HomeListItem)
        ((HomeListItem)view).bind(data);
   
  }

  
  
  
  public int getCount()
  {	 
    return super.getCount();
  }

  public int getItemViewType(int position)
  {
    if (position < this.mHeaderViewCount)
    	return LIST_ITEM_TYPE_HEADER;
    else
   
    	return LIST_ITEM_TYPE_ITEM;
    
  } 

  public View getView(int position, View convertView, ViewGroup parent)
  {
	
	//Log.v("get view" + position);
    if (convertView == null)
    {
      if (position < this.mHeaderViewCount)
      {
    	  convertView = LayoutInflater.from(this.mContext).inflate(R.layout.main_tab_header_view, parent, false);
    	  bindView(convertView, position, null);
      }
        
      if (position >= this.mHeaderViewCount)
      {
    	  convertView = LayoutInflater.from(this.mContext).inflate(R.layout.home_list_item, parent, false);
    	  bindView(convertView, position, (HomeInfo)getItem(position - this.mHeaderViewCount));
      }  
    }
    
    return convertView;   
  }

  public int getViewTypeCount()
  {
    return LIST_ITEM_TYPE_COUNT;
  }

  public boolean isEnabled(int paramInt)
  {
    if (paramInt >= this.mHeaderViewCount)
    	return true;
    return false;
    
  }

  public View newView(Context context, HomeInfo homeInfo, ViewGroup parent)
  {
	  return null;
  }


}

